<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\model\ArticleModel;
use think\Request;
use think\View;

class Article extends Frontend
{
	public function index(){
		echo '<script>window.close();</script>';
	}

	//侧边栏推荐
	public function recommendArticle(){
		$data = (new ArticleModel)->getRecommendArticle();
		return json(['status'=>0,'msg'=>'成功','data'=>$data]);
	}

	//获取文章的详情
	public function getArticleById(Request $request = null){
		$id = $request->param("id",0);
		// dump( $request->param("category_id",0) );die();
		$article = (new ArticleModel)->getArticleById($id);

		return json(['status'=>200,'msg'=>'成功','data'=>$article]);
	}

	//获取首页文章
	public function indexArticle(){
		$data = (new ArticleModel)->getIndexArticle();
		return json(['status'=>200,'msg'=>'成功','data'=>$data]);
	}


	//获取首页推荐
	public function indexResources(){
		$data = (new ArticleModel)->getIndexResources();
		return json(['status'=>200,'msg'=>'成功','data'=>$data]);
	}

	//搜索页面
	public function search(Request $request = null){
		$param = $request->param();
		$data = (new ArticleModel)->getSearch($param);
		return json(['status'=>200,'msg'=>'成功','data'=>$data]);
	}

	//增加文章浏览量
	public function addArticleBrowse(Request $request = null){
		$param = $request->param();
		$data = (new ArticleModel)->addArticleBrowse($param['id']);
		return json(['status'=>200,'msg'=>'成功','data'=>[]]);
	}


	public function getArticleCommentById(Request $request = null){
		$id = $request->param("id",0);
		return view("commentbox",['id'=>$id]);
	}

	public function commentbox(Request $request = null){
		$id = $request->param("id",0);
		return view("commentbox");
	}
}
